script crash explorer but not mozilla`

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • thomas

    script crash explorer but not mozilla`

    HI
    I've written a simpole script to open a new window with an image and
    resize the window depending on the image size: it is

    function fitToSize()
    {
    if( window.document .images )
    window.resizeTo (window.documen t.images[0].width+100,
    window.document .images[0].height+50);
    }

    function animUrl(url)
    {
    var p = 'scrollbars=yes ,resizable=yes, toolbar=no,' +
    'menubar=no,sta tus=no,location =no,left=85,top =20';

    var win = window.open("", "animWindow",p) ;
    win.document.wr iteln('<html>') ;
    win.document.wr iteln('<head>') ;
    win.document.wr iteln('<link type="text/css" rel="stylesheet "
    href="../style/styleThomas.css ">');
    win.document.wr iteln('<script
    src="../js/animWindow.js"> </script>');
    win.document.wr iteln('</head>');
    win.document.wr iteln('<body id="animWindow "
    onload="fitToSi ze();">');
    win.document.wr iteln('<img name ="imgTag" class="center" src="' +
    url + '">');
    win.document.wr iteln('<p><a href="javascrip t:;"
    onclick="self.c lose();">Close window</a></p>');
    win.document.wr iteln('</body>');
    win.document.wr iteln('</html>');
    win.document.cl ose();
    //win.resizeTo(wi n.document.imag es[0].width,200);
    win.focus();

    return false;
    }

    It is very simple. I call it with the following in the html pages:
    <a href="javascrip t:;" onclick="return animUrl('image. gif');">A Gif
    image</a>

    Clicking on the link crash explorer that immediately freezes.
    It works well everywhere else, excpet Opera that complain with an
    obnoxious message.

    Does anybody see what's obviously wrong in my code?
    Thanks

    Thomas
  • Michael Winter

    #2
    Re: script crash explorer but not mozilla`

    "thomas" wrote on 10/11/2003:
    [color=blue]
    > HI
    > I've written a simpole script to open a new window with an image and
    > resize the window depending on the image size: it is
    >
    > function fitToSize()
    > {
    > if( window.document .images )
    > window.resizeTo (window.documen t.images[0].width+100,
    > window.document .images[0].height+50);
    > }
    >
    > function animUrl(url)
    > {
    > var p = 'scrollbars=yes ,resizable=yes, toolbar=no,' +
    > 'menubar=no,sta tus=no,location =no,left=85,top =20';
    >
    > var win = window.open("", "animWindow",p) ;
    > win.document.wr iteln('<html>') ;
    > win.document.wr iteln('<head>') ;
    > win.document.wr iteln('<link type="text/css" rel="stylesheet "
    > href="../style/styleThomas.css ">');
    > win.document.wr iteln('<script
    > src="../js/animWindow.js"> </script>');
    > win.document.wr iteln('</head>');
    > win.document.wr iteln('<body id="animWindow "
    > onload="fitToSi ze();">');
    > win.document.wr iteln('<img name ="imgTag" class="center" src="'[/color]
    +[color=blue]
    > url + '">');
    > win.document.wr iteln('<p><a href="javascrip t:;"
    > onclick="self.c lose();">Close window</a></p>');
    > win.document.wr iteln('</body>');
    > win.document.wr iteln('</html>');
    > win.document.cl ose();
    > //win.resizeTo(wi n.document.imag es[0].width,200);
    > win.focus();
    >
    > return false;
    > }
    >
    > It is very simple. I call it with the following in the html pages:
    > <a href="javascrip t:;" onclick="return animUrl('image. gif');">A Gif
    > image</a>
    >
    > Clicking on the link crash explorer that immediately freezes.
    > It works well everywhere else, excpet Opera that complain with an
    > obnoxious message.
    >
    > Does anybody see what's obviously wrong in my code?
    > Thanks
    >
    > Thomas[/color]

    I don't get a crash, but I do get an 'access denied' error. I think
    it's because of a violation of the 'Same Origin Policy': you can't
    access properties in a window or frame that didn't originate from the
    same domain as the accessing document. As there is no URL at all, IE
    probably assumes that no-one should get access - but that's just a
    guess. I had the same problem, but there is a simple solution:
    include a variable on the calling page that the image window can use
    to get the URL. You could actually write a HTML page (rather that
    generate one entirely at run-time) that only fills-in the image
    source:

    <!-- Your !DOCTYPE, HEAD, BODY, etc. for the image window -->
    <SCRIPT type="text/javascript">
    <!--
    document.writel n( '<IMG src="' + window.opener.i mageURL + '">' );
    // -->
    </SCRIPT>
    <!-- The rest of your document -->

    Hope you have better luck,
    Mike

    --
    Michael Winter
    M.Winter@[no-spam]blueyonder.co.u k (remove [no-spam] to reply)


    Comment

    • thomas

      #3
      Re: script crash explorer but not mozilla`

      I did exactly what you said and it works.
      My only regret is that I have to declare this variable imageURL in
      every page that use this script.
      But thank you very much, since Explorer does not crash anymore.

      Thomas

      "Michael Winter" <M.Winter@[no-spam]blueyonder.co.u k> wrote in message news:<16Vrb.166 5$A71.12450880@ news-text.cableinet. net>...[color=blue]
      > "thomas" wrote on 10/11/2003:
      >
      > I don't get a crash, but I do get an 'access denied' error. I think
      > it's because of a violation of the 'Same Origin Policy': you can't
      > access properties in a window or frame that didn't originate from the
      > same domain as the accessing document. As there is no URL at all, IE
      > probably assumes that no-one should get access - but that's just a
      > guess. I had the same problem, but there is a simple solution:
      > include a variable on the calling page that the image window can use
      > to get the URL. You could actually write a HTML page (rather that
      > generate one entirely at run-time) that only fills-in the image
      > source:
      >
      > <!-- Your !DOCTYPE, HEAD, BODY, etc. for the image window -->
      > <SCRIPT type="text/javascript">
      > <!--
      > document.writel n( '<IMG src="' + window.opener.i mageURL + '">' );
      > // -->
      > </SCRIPT>
      > <!-- The rest of your document -->
      >
      > Hope you have better luck,
      > Mike[/color]

      Comment

      Working...